/*
    BibleNotebook - A bible reader software
    Copyright (C) 2014  Williams Fernando Lopez

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
 */

package com.simplebible.dictionary.objects;


/**
 *
 * @author Williams Lopez
 */
public class SimpleIndex extends NodeIndex{
    

    public NodeIndex findNodeByKey(String key){
        return findNodeByKeyRecursive(this, key,false);
    }

    private NodeIndex findNodeByKeyRecursive(NodeIndex node, String key, boolean leaf){
        if (node.getValue() != null && node.getValue().equals(key)) {
            return node;
        }

        if(node.getChildren()!=null){
            for(NodeIndex n:node.getChildren()){
                NodeIndex ne = findNodeByKeyRecursive(n, key,leaf);
                if(ne!=null){
                    return ne;
                }
            }
        }

        return null;
    }

}
